//公共
import myHeader from "/pages/headerfoot/pages/header.vue"
//表格
import uniForms from "/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
//语言
import Lang from '@/utils/lang.js';
//公共公益方法
import commonBenefit from '@/common/commonbenefit.js';
//公共方法
import Base from '@/common/base.js';
//微信api
import weChat from '@/lib/wechat.js';
//登录api
import Login from '@/lib/login.js';
//用户
import User from '@/lib/user.js';
//公共底部
import Tabbar from "/pages/headerfoot/pages/benefitfooter.vue";
//cache缓存
import Cache from '@/utils/cache.js';

export default {
	components: {
		myHeader,
		uniForms,
		Tabbar
	},
	data() {
		return {
			informationfilling: Lang.lang.informationfilling,
			lang: Lang.lang, //语言1
			code:'',//激活码
			ifshow: true, //是否显示
		}
	},
	// 分享到朋友
	onShareAppMessage(res) {
		weChat.onShareAppMessage(Lang.lang.benefittitle, Lang.lang.ShareAppMessagedesc, commonBenefit
			.automaticurl(
				'benefitindex'));
	},
	// 分享到朋友圈
	onShareTimeline(res) {
		weChat.onShareTimeline(Lang.lang.benefittitle, commonBenefit.automaticurl('benefitindex'));
	},
	onShow() {
		var that = this;
		that.ifreglogin();
	},
	methods: {
		//判断是否需要注册或者登录与其他
		async ifreglogin() {
			var that = this;
			//注册
			await Base.globalauthorization();
		}, 
		//输入
	  onKeyInput(val) {
		  var that=this;
		  that.code=val.detail.value;
		},
		//激活码
		mycode() {
			uni.navigateTo({
				url: commonBenefit.automaticurl('mycodelist'),
			})
		},
		//提交
		submit() {
			 var that=this;
			if(that.code){
				var data = {};
				data['user_id'] = Cache.get('userid');
				data['activation_code'] =that.code;
				commonBenefit.StudentActivationApiMethod(data).then(ress => {
					if (ress) {
						uni.showModal({
							title: '提示',
							title: ress.msg,
							showCancel:false,
							success: function(res) {
							    if (res.confirm) {
									 console.log('用户点击确定');
							      // if(ress.code==1){
							      // 	uni.redirectTo({
							      // 		url:commonBenefit.automaticurl('mycodelist')
							      // 	})
							      // } 
							    } else if (res.cancel) {
							      console.log('用户点击取消');
							    }
							  }
						})
						
						
					}
				});
			}else{
				uni.showToast({
					icon:"none",
					title: '激活码不能未空',
					duration: 2000
				});
			}
		},
	}
}